package ch09;

import java.util.Calendar;

class _30_CalendarEx7 {
	public static void main(String[] args) {
		int year = 2014;
		int month = 8;

		Calendar sDay = Calendar.getInstance();
		Calendar eDay = Calendar.getInstance();

		sDay.set(year, month - 1, 1);
		eDay.set(year, month - 1, sDay.getActualMaximum(Calendar.DATE));
		sDay.add(Calendar.DATE, -sDay.get(Calendar.DAY_OF_WEEK) + 1);
		eDay.add(Calendar.DATE, 7 - eDay.get(Calendar.DAY_OF_WEEK));

		System.out.println("      " + year + "년 " + month + "월");
		System.out.println(" SU MO TU WE TH FR SA");

		for (int n = 1; sDay.before(eDay) || sDay.equals(eDay); 
				sDay.add(Calendar.DATE, 1)) {
			int day = sDay.get(Calendar.DATE);
			System.out.print((day < 10) ? "  " + day : " " + day);
			if (n++ % 7 == 0) System.out.println();
		}
	}
}
/*
      2014년 8월
 SU MO TU WE TH FR SA
 27 28 29 30 31  1  2
  3  4  5  6  7  8  9
 10 11 12 13 14 15 16
 17 18 19 20 21 22 23
 24 25 26 27 28 29 30
 31  1  2  3  4  5  6
*/